/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.openmrs.module.basicmodule.DSS.Interpreter.Function.Time;

import org.openmrs.module.basicmodule.DSS.Interpreter.DSSObservation;
import org.openmrs.module.basicmodule.DSS.Interpreter.Function.Function;
import java.util.ArrayList;
import java.util.ListIterator;
import org.openmrs.module.basicmodule.DSS.Interpreter.InterpreterVisitor;
import org.openmrs.module.basicmodule.DSS.ast.AST;
/**
 *
 * @author David
 */
public class RecentTimeItemFunction extends Function{

    @Override
    public Object execute(ArrayList args) {

        ArrayList<DSSObservation> d = (ArrayList<DSSObservation>) ((AST)args.get(0)).accept(new InterpreterVisitor());
        ListIterator li = d.listIterator();

        DSSObservation currentRecent = d.get(0);
        DSSObservation dssob;
        while (li.hasNext()){
            dssob = (DSSObservation) li.next();
            if(dssob.getDate().before(currentRecent.getDate())) {
                currentRecent = dssob;
            }
        }

        return currentRecent;
    }
}
